<?php

declare(strict_types=1);

namespace App\Traits\Model\Orders;

use App\Model\App\App;
use App\Scopes\Orders\OrderAction as OrderActionScope;
use Hyperf\Context\Context;

trait OrderAction
{
    /**
     * The "booting" method of the model.
     */
    protected function boot():void
    {
        parent::boot();
        static::addGlobalScope(new OrderActionScope);
    }

    /**
     * 设置店铺ID
     * @param $value
     */
    public function setShopIdAttribute($value)
    {
        if (!$value) {
            $value = match (getApp()) {
                'api' => getShop('id')
            };
        }

        $this->attributes['shop_id'] = $value;
    }
}
